﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommonFunc;

public partial class Manageweb_ManageGBook_ManageGBook : System.Web.UI.Page
{
    MODEL.GBook MGB = new MODEL.GBook();
    MODEL.GBook _MGB = new MODEL.GBook();

    BLL.GBook BGB = new BLL.GBook();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["MasterID"] == null)
        {
            Response.Redirect("../Default.aspx");
        }

        TABLE_Details.Visible = false;
    }


    #region 查看留言详细表格数据初始化 [初始化]
    protected void PageDataInit()
    {
        try
        {
            if (LB_ID.Text != "")
            {
                MGB.GBook_ID = Convert.ToInt32(LB_ID.Text);
                _MGB = BGB.GetGBookByID(MGB);

                LB_Content.Text = _MGB.GBook_Content;
                LB_DateTime.Text = _MGB.GBook_DateTime.ToString();
                LB_Email.Text = _MGB.GBook_Email;
                LB_IP.Text = _MGB.GBook_IP;
                LB_Name.Text = _MGB.GBook_Name;
                LB_QQ.Text = _MGB.GBook_QQ;
                LB_State.Text = FormatState((object)_MGB.GBook_State);
                LB_Tel.Text = _MGB.GBook_Telephone;
                LB_Title.Text = _MGB.GBook_Title;
            }
        }
        catch (Exception ex)
        {
            LB_ManageGBook.Text = ex.Message;
        }
    }
    #endregion


    #region 留言状态 [格式化]
    protected string FormatState(object _State)
    {
        bool State = Convert.ToBoolean(_State);
        if (State)
        {
            return "已启用";
        }
        else
        {
            return "已锁定";
        }
    }
    #endregion


    #region 留言回复 [格式化]
    protected string FormatReply(object _Reply)
    {
        string Reply = Convert.ToString(_Reply);
        if (Reply == "")
        {
            return "未回复";
        }
        else
        {
            return "已回复";
        }
    }
    #endregion


    #region 显示状态切换 [Command] [GridView]
    protected void Btn_State_Command(object sender, CommandEventArgs e)
    {
        try
        {
            MGB.GBook_ID = Convert.ToInt32(e.CommandArgument);

            BGB.ModState(MGB);

            GV_GBookList.DataBind();
        }
        catch (Exception ex)
        {
            LB_ManageGBook.Text = ex.Message;
        }
    }
    #endregion
    #region 查看留言详细 [Command] [GridView]
    protected void LBtn_View_Command(object sender, CommandEventArgs e)
    {
        try
        {
            TABLE_Details.Visible = true;

            LB_ID.Text = e.CommandArgument.ToString();

            PageDataInit();
        }
        catch (Exception ex)
        {
            LB_ManageGBook.Text = ex.Message;
        }
    }
    #endregion
    #region 删除留言 [Command] [GridView]
    protected void LBtn_Del_Command(object sender, CommandEventArgs e)
    {
        try
        {
            MGB.GBook_ID = Convert.ToInt32(e.CommandArgument);

            BGB.Del(MGB);

            LB_ManageGBook.Text = "删除成功";

            GV_GBookList.DataBind();
        }
        catch (Exception ex)
        {
            LB_ManageGBook.Text = ex.Message;
        }
    }
    #endregion


    #region 管理员回复 [Click]
    protected void Btn_Reply_Click(object sender, EventArgs e)
    {
        try
        {
            MGB.GBook_Reply = CommonFunction.CharConvert(TB_Reply.Text);

            MGB.GBook_ID = Convert.ToInt32(LB_ID.Text);

            BGB.Reply(MGB);

            LB_ManageGBook.Text = "回复成功";

            GV_GBookList.DataBind();
        }
        catch (Exception ex)
        {
            LB_ManageGBook.Text = ex.Message;
        }
    }
    #endregion
    
}
